package create.simplefactory;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

/**
 * @author pengcheng
 * @version V1.0
 * @description
 * @date 2019/10/26 16:47
 */
public class ReflectDemo {
    public ReflectDemo() {
    }

    public static ReflectDemo getInstance() {
        return FactoryInstance.instance;
    }

    private static class FactoryInstance {
        private static ReflectDemo instance = new ReflectDemo();
    }

    public Pizza creatPizza(String flag) throws Exception {
        String name = getProperties(flag);
        Class<?> c = Class.forName(name);
        Pizza o = (Pizza) c.newInstance();
        return o;
    }

    private String getProperties(String type) {
        Properties pro = new Properties();
        InputStream in = ClassLoader.getSystemResourceAsStream("simplefactrory.properties");
        try {
            pro.load(in);
        } catch (IOException e) {
            e.printStackTrace();
        }
        return pro.getProperty(type);
    }
}
